package com.gitee.huxing.course.conc.task;

import java.util.concurrent.CountDownLatch;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.conc.task
 * @ClassName: TaskService01Impl
 * @Author: huxing
 * @DateTime: 2021-08-25 下午4:58
 */
public class TaskThreadPool04 extends AbstractTaskThreadPool{

    public static void main(String[] args) throws InterruptedException{
        new TaskThreadPool04().task();
    }

    @Override
    public int threadTask() {
        final int[] result = new int[1];
        Thread thread1 = new Thread(() -> {
            result[0] = CourseTask.sum();
        });
        try {
            thread1.start();
            // 等待直到线程结束
            while (thread1.isAlive()){
                Thread.sleep(1000L);
            }
        } catch (InterruptedException ex){
            ex.printStackTrace();
        }
        return result[0];
    }
}
